home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / WZUN11SR.ARJ / WIZUNZIP.C < prev    next >
C/C++ Source or Header  |  1992-01-24  |  11KB  |  272 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: WizUnzip.c
  4.  
  5.     PURPOSE:  Windows Info-ZIP Unzip, an Unzipper for Windows
  6.     FUNCTIONS:
  7.  
  8.         WinMain() - calls initialization function, processes message loop
  9.         WizUnzipInit() - initializes window data and registers window
  10.         WizUnzipWndProc() - processes messages
  11.         About() - processes messages for "About" dialog box
  12.  
  13.     AUTHOR: Robert A. Heath,  157 Chartwell Rd. Columbia, SC 29210
  14.     I place this source module, WizUnzip.c, in the public domain.  Use it as you will.
  15. ****************************************************************************/
  16.  
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <time.h>                
  20. #include <string.h>             
  21. #include <windows.h>    /* required for all Windows applications */
  22. #include <assert.h>    
  23. #include "wizunzip.h"                /* specific to this program              */
  24.  
  25.  
  26. #define MAXLISTBOXLINES 200 /* max records in list box     */
  27.  
  28. static char FIRSTUSE[] = "FirstUse"; /* first use keyword in WIN.INI */
  29. char FORMAT_KEY[] = "Format";         /* Format keyword in WIN.INI        */
  30. char OVERWRITE_KEY[] = "Overwrite";    /* Overwrite keyword in WIN.INI        */
  31. char TRANSLATE_KEY[] = "Translate";    /* Translate keyword in WIN.INI        */
  32. char LBSELECTION_KEY[] = "LBSelection";    /* LBSelection keyword in WIN.INI */
  33. char RECREATE_DIRS_KEY[] = "Re-createDirs"; /* re-create directory structure WIN.INI keyword             */
  34. char UNZIP_TO_ZIP_DIR_KEY[] = "UnzipToZipDir"; /* unzip to .ZIP dir WIN.INI keyword */
  35.                                                 
  36. /* Values for listbox selection WIN.INI keyword
  37.  */
  38. char *LBSelectionTable[] = {
  39.     "extract", "display", "test" 
  40. };
  41. #define LBSELECTIONTABLE_ENTRIES (sizeof(LBSelectionTable)/sizeof(char *))
  42.  
  43. HANDLE hInst;                       /* current instance                      */
  44. HMENU  hMenu;                /* main menu handle            */
  45. HANDLE hAccTable;
  46.  
  47. HANDLE hHourGlass;              /* handle to hourglass cursor         */
  48. HANDLE hSaveCursor;              /* current cursor handle         */
  49. HANDLE hHelpCursor;            /* help cursor                        */
  50. HANDLE hFixedFont;            /* handle to fixed font                */
  51. HANDLE hOldFont;            /* handle to old font                */
  52.  
  53. int hFile;                  /* file handle             */
  54. HWND    hMainWnd;          /* the main window handle.                 */
  55. HWND hWndHeaderLine1;              /* list box header line 1 handle    */
  56. HWND hWndHeaderLine2;              /* list box header line 1 handle    */
  57. HWND    hWndList;              /* list box handle        */
  58. HWND hWndTotalLine1;              /* list box total line 1 handle    */
  59. HWND hWndTotalLine2;              /* list box total line 2 handle    */
  60. HWND hWndStatus;        /* status    (a.k.a. Messages) window */
  61. HWND hDlgAbout;                /* handle to about box                */
  62. HWND hExtract;            /* extract button                */
  63. HWND hDisplay;            /*display button                */
  64. HWND hTest;                /* test button                */
  65. HWND hShowComment;            /* show comment button            */
  66. BOOL bHelp = FALSE;        /* Shift-F1 has been struck when TRUE        */
  67.  
  68. /* Global values defined by WIN.INI settings:
  69.  */
  70. BOOL bRecreateDirs;    /* re-create directory structures when TRUE */
  71. BOOL bTranslate = FALSE;    /* translate LF to CR-LF                    */
  72. WORD wFormat = 0;        /* display format: 0 = short, 1 = long */
  73. BOOL bOverwrite = FALSE;    /* overwrite or prompt: IDM_OVERWRITE, IDM_PROMPT */
  74. BOOL bUnzipToZipDir = FALSE; /* unzip only to .ZIP directory        */
  75. WORD wLBSelection = IDM_LB_DISPLAY;    /* default listbox selection action */
  76.  
  77.  
  78. BOOL bStatusMaxed = FALSE;    /* status box is maximized        */
  79.  
  80. RECT Rect;                  /* dimension of the client window  */
  81. HWND hDlgHelp;                    /* Help dialog handler         */
  82.  
  83. HBRUSH hBrush ;            /* brush for  standard window backgrounds  */
  84.  
  85. /* File and Path Name variables
  86.  */
  87. char szAppName[] = "WizUnzip";        /* application title        */
  88. char szStatusClass[] = "MsgWndw";/* status window class    */
  89. char szFileName[80] = "";    /* fully-qualified file name in OEM char set */
  90. char szDirName[MAX_DIRNAME_LEN+1] = "";  /* resultant Directory Name    */
  91. char szOrigDirName[MAX_DIRNAME_LEN+1];    /* original directory name        */
  92. int ofretval;        /* return value from initial open if filename given */
  93.  
  94. WORD    TotalZippedFiles;        /* total personal records in file    */
  95. WORD     ListBoxLines; /* max list box lines showing on screen */
  96. WORD MessageWinLines; /* max visible lines on message window  */
  97. WORD wCommentLength ;            /* length of comment in .ZIP file    */
  98.  
  99. /* Client window size factors:
  100.  */
  101. #ifdef NEEDME
  102. short nLBVscrollMax;
  103. short nLBVscrollPos = 0;
  104. short nLBVscrollInc;    /* vertical scroll incr    */
  105. #endif
  106.  
  107.  
  108.  
  109. /* Forward References
  110.  */
  111. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  112. long FAR PASCAL WizUnzipWndProc(HWND, unsigned, WORD, LONG);
  113.  
  114.  
  115. /****************************************************************************
  116.  
  117.     FUNCTION: DoCaption(HWND hWnd,  PSTR szOemFileName)
  118.                 szFileName is OEM char set.
  119.  
  120.     PURPOSE: Set new caption for main window
  121.  
  122. ****************************************************************************/
  123. void 
  124. DoCaption(HWND hWnd, PSTR szOemFileName)
  125. {
  126. WORD wMenuState;
  127. char szSimpleFileName[15];    /* just the 8.3 part in ANSI char set */
  128. char szCaption[100];
  129. PSTR pFileName;        /* pointer to simple filename                */
  130. BOOL    bIconic = IsIconic(hWnd);    /* is window iconic ?    */
  131.  
  132.     /* point to simple filename in OEM char set                    */
  133.     if ((pFileName = strrchr(szOemFileName, '\\')) ||
  134.         (pFileName = strrchr(szOemFileName, ':')))
  135.             pFileName++;    /* point to filename                */
  136.  
  137.     else
  138.             pFileName = szOemFileName;
  139.  
  140.     OemToAnsi(pFileName, szSimpleFileName);
  141.     (void)wsprintf(szCaption, "%s - %s %s %s", 
  142.                     (LPSTR)szAppName, 
  143.                     (LPSTR)(szSimpleFileName[0] ? 
  144.                         szSimpleFileName : "(No .ZIP file)"),
  145.                     (LPSTR)(!bIconic && szOrigDirName[0] ? " - " : ""),
  146.                     (LPSTR)(!bIconic ? szOrigDirName : ""));
  147.     SetWindowText(hWnd, (LPSTR)szCaption);
  148.     wMenuState = (WORD)(szSimpleFileName[0] ? MF_ENABLED : MF_GRAYED) ;
  149.     EnableMenuItem(hMenu, IDM_SELECT_ALL, wMenuState|MF_BYCOMMAND); 
  150.     EnableMenuItem(hMenu, IDM_DESELECT_ALL, wMenuState|MF_BYCOMMAND); 
  151. }
  152.  
  153. /****************************************************************************
  154.  
  155.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  156.  
  157.     PURPOSE: calls initialization function, processes message loop
  158.  
  159.     COMMENTS:
  160.  
  161.         This will initialize the window class if it is the first time this
  162.         application is run.  It then creates the window, and processes the
  163.         message loop until a WM_QUIT message is received.  It exits the
  164.         application by returning the value passed by the PostQuitMessage.
  165.  
  166. ****************************************************************************/
  167.  
  168. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  169. HANDLE hInstance;                            /* current instance             */
  170. HANDLE hPrevInstance;                        /* previous instance            */
  171. LPSTR lpCmdLine;                             /* command line                 */
  172. int nCmdShow;                                /* show-window type (open/icon) */
  173. {
  174.     HWND hWnd;                               /* window handle                */
  175.     MSG msg;                                 /* message                      */
  176.     int    i;        /* index into name                */
  177.     OFSTRUCT OfStruct;                    /* open file structure            */
  178.     char szBuffer[64];                    /* option strings from WIN.INI    */
  179.  
  180.  
  181.     if (!hPrevInstance)                 /* Has application been initialized? */
  182.         if (!WizUnzipInit(hInstance))
  183.             return (NULL);              /* Exits if unable to initialize     */
  184.  
  185.  
  186.     if (_fstrlen(lpCmdLine))            /* if filename passed on start-up    */
  187.     {
  188.          if ((ofretval = OpenFile(lpCmdLine, &OfStruct, OF_EXIST)) >= 0)
  189.         {
  190.             strcpy(szFileName, OfStruct.szPathName); /* save file name    */
  191.         }
  192.     }
  193.     /* Get initial Re-create dirs format
  194.      */
  195.     GetProfileString(szAppName, RECREATE_DIRS_KEY, "no", szBuffer, sizeof(szBuffer));
  196.     bRecreateDirs = (BOOL)(!stricmp(szBuffer, "yes"));
  197.  
  198.     /* Get translate flag
  199.      */
  200.     GetProfileString(szAppName, TRANSLATE_KEY, "no", szBuffer, sizeof(szBuffer));
  201.     bTranslate = (BOOL)(!stricmp(szBuffer, "yes"));
  202.  
  203.     /* Get initial display format: short or long
  204.      */
  205.     GetProfileString(szAppName, FORMAT_KEY, "long", szBuffer, sizeof(szBuffer));
  206.     wFormat = (WORD)(!stricmp(szBuffer, "long") ? 1 : 0);
  207.  
  208.     /* Get overwrite option: yes=IDM_OVERWRITE, no=IDM_PROMPT            */
  209.     GetProfileString(szAppName, OVERWRITE_KEY, "no", szBuffer, sizeof(szBuffer));
  210.     bOverwrite = (BOOL)(!stricmp(szBuffer, "yes"));
  211.  
  212.     /* Get Unzip to .ZIP dir option: yes or no                             */
  213.     GetProfileString(szAppName, UNZIP_TO_ZIP_DIR_KEY, "no", szBuffer, sizeof(szBuffer));
  214.     bUnzipToZipDir = (BOOL)(!stricmp(szBuffer, "yes"));
  215.  
  216.     /* Get default listbox selection operation
  217.      */
  218.     GetProfileString(szAppName, LBSELECTION_KEY, "display", 
  219.                         szBuffer, sizeof(szBuffer));
  220.  
  221.     for (i = 0; i < LBSELECTIONTABLE_ENTRIES &&
  222.         stricmp(LBSelectionTable[i], szBuffer) ; i++)
  223.         ;
  224.  
  225.     wLBSelection = IDM_LB_DISPLAY;        /* assume default is to display        */
  226.     if (i < LBSELECTIONTABLE_ENTRIES)
  227.         wLBSelection = IDM_LB_EXTRACT + i;
  228.  
  229.     hWnd = CreateWindow(szAppName,                /* window class            */
  230.          szAppName,                                /* window name             */
  231.         WS_OVERLAPPEDWINDOW,                      /* window style            */
  232.         0,                                                /* x position              */
  233.         0,                                                /* y position              */
  234.         CW_USEDEFAULT,                            /* width                   */
  235.         0,                                               /* height                  */
  236.         NULL,                                     /* parent handle           */
  237.         NULL,                                     /* menu or child ID        */
  238.         hInstance,                                /* instance                */
  239.         NULL);                                    /* additional info         */
  240.  
  241.     if (!hWnd)                                    /* Was the window created? */
  242.         return (NULL);
  243.  
  244.     hMainWnd = hWnd;        /* globalize the main window                */
  245.     /* On first usage, throw up About box, saying what WizUnzip is, etc.
  246.      */
  247.     GetProfileString(szAppName, FIRSTUSE, "yes", 
  248.                  szBuffer, sizeof(szBuffer));
  249.     if (!stricmp(szBuffer, "yes"))
  250.     {
  251.         WriteProfileString(szAppName,FIRSTUSE, "no");
  252.         PostMessage(hWnd, WM_COMMAND, IDM_ABOUT, 0L);
  253.     }
  254.        hHelpCursor = LoadCursor(hInstance,"HelpCursor");
  255.  
  256.     ShowWindow(hWnd, nCmdShow);                   /* Shows the window        */
  257.     UpdateWindow(hWnd);                           /* Sends WM_PAINT message  */
  258.  
  259.      while (GetMessage(&msg,        /* message structure                      */
  260.             NULL,                  /* handle of window receiving the message */
  261.             NULL,                  /* lowest message to examine              */
  262.             NULL))                 /* highest message to examine             */
  263.     {
  264.         if (!TranslateAccelerator(hWnd, hAccTable, &msg))
  265.         {
  266.             TranslateMessage(&msg);    /* Translates virtual key codes    */
  267.             DispatchMessage(&msg);     /* Dispatches message to window    */
  268.         }
  269.     }
  270.     return (msg.wParam);           /* Returns the value from PostQuitMessage */
  271. }
  272.